-
Notifications
You must be signed in to change notification settings - Fork 223
Explicitly handle switch expressions in parser #12500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| LessThan;[<]; | ||
| Identifier;[span]; | ||
| GreaterThan;[>]; | ||
| Identifier;[some]; | ||
| Whitespace;[ ]; | ||
| LessThan;[<]; | ||
| Identifier;[i]; | ||
| GreaterThan;[>]; | ||
| Identifier;[html]; | ||
| LessThan;[<]; | ||
| CSharpOperator;[/]; | ||
| Identifier;[i]; | ||
| GreaterThan;[>]; | ||
| LessThan;[<]; | ||
| CSharpOperator;[/]; | ||
| Identifier;[span]; | ||
| GreaterThan;[>]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure, we're saying that this is interpreted as C#, not razor? That seems reasonable, but just wanted to make sure that's what was intended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, once inside a switch expression everything is parsed as C# and you can't drop into HTML.
| Accept(in read); | ||
| return; | ||
| } | ||
| else if (At(SyntaxKind.Keyword)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure that ParseStatement will handle all possible locations here. What if it's an embedded expression inside a @(), for example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, so I tried that and it actually just works. Because we don't allow you to drop to HTML inside an explicit expression, we don't have to do any special handling for it.
I added some tests to cover it too.
davidwengier
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed early, this is valid in Razor files today:
@{
RenderFragment x = val switch
{
true => @<div></div>,
false => @<div></div>
};
}
Would be good to add a test, even if it's skipped for now, with what that looks like now, and what it looks like with a less than as the first character in the first arm
Fixes #7230